﻿using System.Collections.ObjectModel;
using NFox.WPF;

#if !WpfApp1
using Autodesk.AutoCAD.ApplicationServices;
#endif

namespace JoinBox.WPF.多文档标签.ViewModel
{
#if WpfApp1
    public class Document
    {
        public Database Database { get; }
        public string Name { get; }
        public bool IsDisposed { get; internal set; }
    }
    public class Database
    {
        public string Filename { get; }
    }
#endif

    /// <summary>
    /// 限制所有高度的初始化值
    /// </summary>
    public class DocumentTab
    {
        public static int Height { set; get; } = 30;
        public static int HeightDPI
        {
            get
            {
                return (int)(Height * DPI.CurrentDPI);
            }
        }

    }

    public class Info : ViewModelBase
    {
        public string InfoDocName { get; set; }

        Document _Document;
        public Document Document
        {
            get { return _Document; }
            set { _Document = value; OnPropertyChanged(); }
        }

        private bool _pick;
        /// <summary>
        /// 选中
        /// </summary>
        public bool Pick
        {
            get { return _pick; }
            set { _pick = value; OnPropertyChanged(); }
        }
    }

    /// <summary>
    /// WPF联动数据
    /// </summary>
    public partial class DocumentTabData : ViewModelBase
    {
        private int _height;
        /// <summary>
        /// 多文档标签窗口高度
        /// </summary>
        public int DocWindowHeight
        {
            get => _height;
            set
            {
                SetProperty(ref _height, value);
            }
        }

        private ObservableCollection<Info> _Infos;
        /// <summary>
        /// 多文档标签集合
        /// </summary>
        public ObservableCollection<Info> Infos
        {
            get => _Infos;
            set
            {
                SetProperty(ref _Infos, value);
            }
        }

        private Info _Info;
        /// <summary>
        /// 用于控制文档按钮选中
        /// </summary>
        public Info Info
        {
            get => _Info;
            set { _Info = value; OnPropertyChanged(); }
        }

        private Document _intput;
        /// <summary>
        /// 按钮选中状态
        /// </summary>
        public Document InputPick
        {
            get { return _intput; }
            set
            {
                _intput = value;
                OnPropertyChanged();

                Info pickitem = null;
                foreach (Info it in Infos)
                {
                    if (it.Document == _intput)
                    {
                        pickitem = it;
                    }
                    else
                    {
                        it.Pick = false;
                    }
                }
                //含有字母,就选中
                if (pickitem != null)
                {
                    pickitem.Pick = true;
                }
            }
        }

        // 以实现数据双向关联
        // 1数据绑定到xaml的cs文件 DataContext= new PipeViewModel();
        // 2资源文件当前找不到,会找上面一层,再找不到,再找再上一层,直到最后根目录.
        public DocumentTabData()
        {
            DocWindowHeight = DocumentTab.Height;
            Infos = new ObservableCollection<Info>();
        }

    }
}
